//
//  EXT+UIBarButtonItem.swift
//  新浪微博
//
//  Created by 季伯文 on 2017/6/29.
//  Copyright © 2017年 bowen. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(imgName: String?, title: String?, target: Any?, action: Selector) {
        
        //实例化一个按钮
        let button = UIButton()
        //添加监听事件
        button.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        
        if let img  = imgName {
            //图片
            button.setImage(UIImage(named:img), for: UIControlState.normal)
            button.setImage(UIImage(named:"\(img)_hightlighted"), for: UIControlState.highlighted)
        }
        
        if let tit = title {
            //标题
            button.setTitle(tit, for: UIControlState.normal)
            button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
            button.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
            button.setTitleColor(UIColor.orange, for: UIControlState.highlighted)
            
        }
        
        button.sizeToFit()
        
        //调用指定函数完成实例化
        self.init(customView: button)
        
        
    }
}
